using System.Collections.Generic;
using UnityEngine;

namespace Function.SkillEditor.Runtime
{
    public class AnimatorRender
    {
        static Dictionary<string, int> _name2Hash = new Dictionary<string, int>();

        public static void Play(Animator animator, AnimationClip animationClip, int layer, float time, float speed)
        {
            if (!_name2Hash.TryGetValue(animationClip.name, out var hash))
            {
                hash = Animator.StringToHash(animationClip.name);
                _name2Hash.Add(animationClip.name, hash);
            }

            animator.speed = speed;
            animator.Play(hash, layer, time);
        }
    }
}